package framework.common;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;


public class DeviceMessage {
	private List<SensorMessage> messages;

	DeviceMessage() {
		this.messages = new LinkedList<SensorMessage>();
	}

	void add(SensorMessage res) {
		messages.add(res);
	}

	List<SensorMessage> getMessages() {
		return messages;
	}

	public List<String> getAttributes() {
		List<String> attributes = new LinkedList<String>();
		for (SensorMessage m : messages) {
			attributes.add(m.getAttribute());
		}
		return attributes;
	}

	public boolean hasAttribute(String attr) {
		for (SensorMessage m : messages) {
			if (m.getAttribute().equals(attr)) {
				return true;
			}
		}
		return false;
	}

	public Object getAttribute(String attr) {
		for (SensorMessage m : messages) {
			if (m.getAttribute().equals(attr)) {
				return m.getValue();
			}
		}
		return null;
	}

//	public void setMessages(List<SensorMessage> messages) {
//		this.messages = messages;
//	}

	SensorMessage[] toArray() {
		SensorMessage[] a = new SensorMessage[messages.size()];
		messages.toArray(a);
		return a;
	}

	@Override
	public String toString() {
		return Arrays.toString(toArray());
	}

}
